﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references

namespace DataAccess
{
    /// <summary>
    /// 数据访问类:TB_XPH
    /// </summary>
    public partial class TB_XPH
    {
        public TB_XPH()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_XPH");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(Model.TB_XPH model)
        {
            model.NID = CommonExecute.GetID(model.GetType().Name);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TB_XPH(");
            strSql.Append("NID,NYP_NID,XPH_MIN,XPH_MAX)");
            strSql.Append(" values (");
            strSql.Append(":NID,:NYP_NID,:XPH_MIN,:XPH_MAX)");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,10),
					new OracleParameter(":NYP_NID", OracleType.Number,10),
					new OracleParameter(":XPH_MIN", OracleType.Number,10),
					new OracleParameter(":XPH_MAX", OracleType.Number,10)};
            parameters[0].Value = model.NID;
            parameters[1].Value = model.NYP_NID;
            parameters[2].Value = model.XPH_MIN;
            parameters[3].Value = model.XPH_MAX;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(Model.TB_XPH model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TB_XPH set ");
            strSql.Append("NYP_NID=:NYP_NID,");
            strSql.Append("XPH_MIN=:XPH_MIN,");
            strSql.Append("XPH_MAX=:XPH_MAX");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NYP_NID", OracleType.Number,10),
					new OracleParameter(":XPH_MIN", OracleType.Number,10),
					new OracleParameter(":XPH_MAX", OracleType.Number,10),
					new OracleParameter(":NID", OracleType.Number,10)};
            parameters[0].Value = model.NYP_NID;
            parameters[1].Value = model.XPH_MIN;
            parameters[2].Value = model.XPH_MAX;
            parameters[3].Value = model.NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_XPH ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public static bool DeleteList(string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_XPH ");
            if (string.IsNullOrEmpty(where))
                strSql.Append(" where " + where + " ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.TB_XPH GetModel(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,NYP_NID,XPH_MIN,XPH_MAX from TB_XPH ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            Model.TB_XPH model = new Model.TB_XPH();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYP_NID"] != null && ds.Tables[0].Rows[0]["NYP_NID"].ToString() != "")
                {
                    model.NYP_NID = decimal.Parse(ds.Tables[0].Rows[0]["NYP_NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["XPH_MIN"] != null && ds.Tables[0].Rows[0]["XPH_MIN"].ToString() != "")
                {
                    model.XPH_MIN = decimal.Parse(ds.Tables[0].Rows[0]["XPH_MIN"].ToString());
                }
                if (ds.Tables[0].Rows[0]["XPH_MAX"] != null && ds.Tables[0].Rows[0]["XPH_MAX"].ToString() != "")
                {
                    model.XPH_MAX = decimal.Parse(ds.Tables[0].Rows[0]["XPH_MAX"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,NYP_NID,XPH_MIN,XPH_MAX ");
            strSql.Append(" FROM TB_XPH ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TB_XPH";
            parameters[1].Value = "NID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

